<?php
//

namespace App\Http\Middleware;

use App\Common\ErrorMsg;
use App\Common\Token;
use Closure;

class TokenAuthenticate
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $token = Token::authorization();

        if ($token === false) {
            echo json_encode([
                'code' => 1006,
                'msg' => ErrorMsg::get_msg(1006),
                'data' => ''
            ]);
            die;
        }

        if ($token === 'token-expired') {
            echo json_encode([
                'code' => 1007,
                'msg' => ErrorMsg::get_msg(1007),
                'data' => ''
            ]);
            die;
        }

        return $next($request);
    }

}